package cc.linker.steplink.crm.commons.utils;

import java.math.BigDecimal;

/**
 * 数字转换
 *
 * @author zhaomengwei
 */
public class NumberUtils {

    public static Long getLong(Object o) {
        if (o == null) {
            return null;
        } else if (o instanceof Long) {
            return (Long) o;
        } else {
            return Long.parseLong(o.toString());
        }
    }

    public static Integer getInteger(Object o) {
        if (o == null) {
            return null;
        } else if (o instanceof Integer) {
            return (Integer) o;
        } else {
            return Integer.parseInt(o.toString());
        }
    }

    /**
     * 金额分转元
     */
    public static String fenToYuan(Long balance) {
        if (balance != null) {
            double v = balance.doubleValue() / 100;
            return new BigDecimal(v).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString();
        }
        return "";
    }
}
